//
//  MinePeiSongViewController.m
//  Experss
//
//  Created by wmwMAC on 17/8/11.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "MinePeiSongViewController.h"
#import "MyOneCell.h"
#import "MyTwoCell.h"

#import "ChongZhiVController.h"//充值
#import "TiXianViewController.h"//提现

#import "MyBankCardController.h"

#import "PeiSongMyMoneyVController.h"
#import "MyConnectPeopleController.h"
#import "PeiSongDuanMyDingDVController.h"
#import "PeiSongSetVController.h"
#import "PeiSongPersonInfoViewController.h"



@interface MinePeiSongViewController ()<UITableViewDelegate ,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong)NSArray *titleArray;
@property (nonatomic, strong)UIButton *rightBtn2;//右侧按钮


@end

@implementation MinePeiSongViewController


-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 0;
    
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;

    [[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 1;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = KShouYeBg;
   [self configureNaBar];
    [self configureViewController];
    
    _titleArray = @[@[@"我的订单"],@[@"我的客服",@"设置"]];
    
}
- (void)configureNaBar {
    //设置导航栏按钮的边距
    _rightBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBtn2.frame= CGRectMake(0, 0, 60, 30);
    [_rightBtn2 setImage:[UIImage imageNamed:@"shouye_xiaoxi"] forState:(UIControlStateNormal)];
    [_rightBtn2 addTarget:self action:@selector(onClickRight) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *btn_right = [[UIBarButtonItem alloc] initWithCustomView:_rightBtn2];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    negativeSpacer.width = -20;
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, btn_right, nil];
    
}

#pragma mark 消息事件
- (void)onClickRight {
    [self.view showTextNoActivity:@"我是消息" timeLength:(1)];
}
- (void)configureViewController {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -64, kScreen_Width, kScreen_Height+20) style:(UITableViewStylePlain)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = KShouYeBg;
    _tableView.scrollEnabled = NO;
    [self.view addSubview:_tableView];
    _tableView.separatorStyle = kSpNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"MyOneCell" bundle:nil] forCellReuseIdentifier:@"MyOneCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"MyTwoCell" bundle:nil] forCellReuseIdentifier:@"MyTwoCell"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 2) {
        return 2;
    }else{
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return 290;
    }else {
        return 60;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }else {
        return 10;
    }
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 10)];
    bgV.backgroundColor = KShouYeBg;
    return bgV;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        MyOneCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyOneCell"];
        cell.selectionStyle = kSeNone;
        
        cell.photoImageV.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tapPhoto = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapPhoto:)];
        [cell.photoImageV addGestureRecognizer:tapPhoto];
        
        
        cell.chongZhiView.userInteractionEnabled = YES;
        cell.tiXainView.userInteractionEnabled = YES;
        cell.yinHangCardView.userInteractionEnabled = YES;
        cell.chongZhiView.tag = 601;
        cell.tiXainView.tag = 602;
        cell.yinHangCardView.tag = 603;
        
        UITapGestureRecognizer *tapV = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOneCellView:)];
        
        UITapGestureRecognizer *tapV2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOneCellView:)];
        
        UITapGestureRecognizer *tapV3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOneCellView:)];
        
        
        [cell.chongZhiView addGestureRecognizer:tapV];
        [cell.tiXainView addGestureRecognizer:tapV2];
        [cell.yinHangCardView addGestureRecognizer:tapV3];
        
        cell.moneyLB.hidden = YES;
        cell.jianTouImageV.hidden = NO;
        cell.yueLB.hidden = YES;
        
        [cell.myMoneyBtn addTarget:self action:@selector(handleMyMoneyAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        cell.messageBtn.hidden = YES;
        return cell;
    }
    else {
        MyTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyTwoCell"];
        cell.selectionStyle = kSeNone;
        if (indexPath.section == 1) {
            cell.titLB.text = _titleArray[0][indexPath.row];
            cell.renZhengLB.hidden = YES;
        }
        if (indexPath.section == 2) {
            cell.titLB.text = _titleArray[1][indexPath.row];
            cell.renZhengLB.hidden = YES;
        }
       
        
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        PeiSongDuanMyDingDVController *p = [[PeiSongDuanMyDingDVController alloc] init];
        p.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:p animated:YES];
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            MyConnectPeopleController  *address = [[MyConnectPeopleController alloc] init];
            UINavigationController *naV =[[UINavigationController alloc] initWithRootViewController:address];
            address.hidesBottomBarWhenPushed = YES;
            [self presentViewController:naV animated:YES completion:nil];
        }
        if (indexPath.row == 1) {
            PeiSongSetVController  *address = [[PeiSongSetVController alloc] init];
            address.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:address animated:YES];
        }
    }
}

#pragma  mark 充值，提现，银行卡的视图轻拍事件
- (void)handleTapOneCellView:(UITapGestureRecognizer *)tap {
    
    if (tap.view.tag == 601) {
        ChongZhiVController *chong = [[ChongZhiVController alloc] init];
        chong.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:chong animated:YES];
    }
    if (tap.view.tag == 602) {
        TiXianViewController *chong = [[TiXianViewController alloc] init];
        chong.hidesBottomBarWhenPushed = YES;
        chong.typePerson = @"peisong";
        [self.navigationController pushViewController:chong animated:YES];
    }
    if (tap.view.tag == 603) {
        MyBankCardController *chong = [[MyBankCardController alloc] init];
        chong.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:chong animated:YES];
    }
}



//进入个人资料
- (void)handleTapPhoto:(UITapGestureRecognizer *)tap {
    PeiSongPersonInfoViewController *pe = [[PeiSongPersonInfoViewController alloc] init];
    pe.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:pe animated:YES];
    
    
}
//进入我的钱包
- (void)handleMyMoneyAction:(UIButton *)btn {
    PeiSongMyMoneyVController *my = [[PeiSongMyMoneyVController alloc] init];
    my.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:my animated:YES];
}

@end
